<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${tabTitle}</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="ins_cfg_info_edit_form">
                    <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33">
                        <div class="label">机构名称</div>
                        <div class="field">
                            <span>${fundRasInsNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <span>${cstNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">身份证号</div>
                        <div class="field">
                            <span id="cstPyNm">${certNo}</span>
                        </div>
                    </div>

                    <div class="fieldBox col_50">
                        <div class="label">证件有效起始日期</div>
                        <div class="field">
                            <input name="certValidSDt" id="certValidSDt" type="text" class="ui-datepicker" value="${certValidSDt}" validate="{required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_50">
                        <div class="label">证件有效终止日期</div>
                        <div class="field">
                            <input name="certValidEDt" id="certValidEDt" type="text" class="ui-datepicker" value="${certValidEDt}">
                            <div><input type="checkbox" name="checkOne" id="checkOne"  <c:if test="${certValidEDt=='长期'}">checked</c:if> value="长期" onchange="enduring(this)">长期</div>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>

                        <div class="fieldBox col_33">
                            <div class="label">开户银行</div>
                            <div class="field">
                                <select name="bkCd" id="bkCd" value="${bkCd}" validate="{required:true}">
                                    <c:if test="${bkCd == null || bkCd == ''}">
                                        <option value="" selected="selected">--请选择--</option>
                                    </c:if>
                                    <c:if test="${bkCd != null && bkCd != ''}">
                                        <option value="">--请选择--</option>
                                    </c:if>
                                    <c:forEach items="${bankList}" var="item">
                                        <c:if test="${item.key == bkCd}">
                                            <option value="${item.key}" selected="selected">${item.value}</option>
                                        </c:if>
                                        <c:if test="${item.key != bkCd}">
                                            <option value="${item.key}">${item.value}</option>
                                        </c:if>
                                    </c:forEach>
                                </select>
                                <span class="requiredSymbol">*</span>
                                <span class="requiredSymbol">单笔限额：<span class="requiredSymbol" id="singleQuota">${singleQuota}</span></span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">银行账号</div>
                            <div class="field">
                                <input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{number:true, maxlength:22, minlength:15}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">预留手机号</div>
                            <div class="field">
                                <input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">二类户开户状态</div>
                            <div class="field">
                                <span>${accResCd}</span>
                            </div>
                        </div>

                    <!-- hide data -->
                    <div class="fieldBox col_100" style="display: none;">
                        <div class="field">
                            <input name="insCode" id="insCode" type="text" class="ui-textbox" value="${insCode}">
                            <input name="fundRasInsId" id="fundRasInsId" type="text" class="ui-textbox" value="${fundRasInsId}">
                            <input name="fundRasInsNm" id="fundRasInsNm" type="text" class="ui-textbox" value="${fundRasInsNm}">
                            <input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
                            <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
                            <input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
                            <input name="certNo" id=certNo type="text" class="ui-textbox" value="${certNo}">
                        </div>
                    </div>
                </div>
                <div id="saveInsCfgDiv" class="btnsBox" style="text-align: center">
                    <span id="saveInsCfg" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    var ligergrid_icbczb;
    var detailFlag = '${detailFlag}';
    var updateFlag = '${updateFlag}';
    var fromCAFlag = '${fromCAFlag}';
    var fromCMFlag = '${fromCMFlag}';
    var singleQuotaMap = '${singleQuotaMap}'; //开户行限额列表
    var certValidEDt;
    $(function(){
        initData();

        $("#bkCd").change(function(){
            var bankNo = $("#bkCd").val();
            var singleQuota = singleQuotaMap[bankNo+""];
            $("#singleQuota").html(singleQuota ? singleQuota : "");
        });
    });

    /**
     * 初始化
     */
    function initData() {
        $("#ins_cfg_info_edit_form").ligerForm({
            validate: true
        });

        disabledInput();
        enableFields();

        if(singleQuotaMap!=""){
            singleQuotaMap = eval("("+singleQuotaMap+")");
        }
        enduring();
    }
    /**
     * 查看详情页面置灰 不可编辑
     **/
    function disabledInput() {

        if(detailFlag == "true") {

            liger.get("certValidSDt").setDisabled();
            liger.get("certValidEDt").setDisabled();
            liger.get("checkOne").setDisabled();
            liger.get("bkCd").setDisabled();
            liger.get("accNo").setDisabled();
            liger.get("mp").setDisabled();
            $("#saveInsCfgDiv").hide();
        }
    }

    /**
     * 是否展示保存按钮
     **/
    function enableFields() {

        if (null != fromCAFlag && "true" == fromCAFlag) {

            $("#saveInsCfgDiv").show();
        }
        if (null != fromCMFlag && "true" == fromCMFlag) {

            $("#saveInsCfgDiv").show();
        }
    }
    //选择长期置灰时间控件
    function enduring(checkbox) {
        if ($("#checkOne").is(':checked')){
            $("#certValidEDt").hide();
            certValidEDt = "长期";
        } else {
            $("#certValidEDt").show();
            certValidEDt = null;
        }
    }
    /**
     * 校验时间格式
     */
    function checkDateFormat(){
        var flag = 0;
        var params = {};
        params["certValidSDt"] = $("#certValidSDt").val();
        params["certValidEDt"] = $("#certValidEDt").val();
        $.ajax({
            type:'get',
            dataType:'json',
            async:false,
            url:'<%=path%>/customer/cstbscinfo/checkCertValid.do',
            data:params,
            success:function(data){
                //$.ligerDialog.SQalert({content: data.info,SQ_type: "success"});
                if(data.success == 1){
                    var oDate1 = new Date($("#certValidSDt").val());
                    var oDate2 = new Date($("#certValidEDt").val());
                    if(oDate1.getTime() < oDate2.getTime()){
                        flag = 1;
                    }
                    else {
                        UIUtils.alertError("证件有效起始日期 不能大于等于 证件有效终止日期");
                    }
                }else{
                    UIUtils.alertError(data.info);
                }
            },
            error:function(data){
                UIUtils.alertError(data.info);
            }
        });
        return flag;
    }

    /**
     * 保存表单数据
     */
    function saveInfo(){

        var ligerForm = liger.get("ins_cfg_info_edit_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();

        if(!$("#certValidSDt").val()){
            top.$.ligerDialog.SQalert({content: "请选择证件有效起始日期！", SQ_type: "error"});
            return false;
        }
        if(null == certValidEDt && !$("#certValidEDt").val()){
            top.$.ligerDialog.SQalert({content: "请选择证件有效终止日期！", SQ_type: "error"});
            return false;
        }
        if(!$("#bkCd").val()){
            top.$.ligerDialog.SQalert({content: "请选择开户银行！", SQ_type: "error"});
            return false;
        }
        if(!$("#accNo").val()){
            top.$.ligerDialog.SQalert({content: "请填写银行账号！", SQ_type: "error"});
            return false;
        }
        if(!$("#mp").val()){
            top.$.ligerDialog.SQalert({content: "请填写预留手机号码！", SQ_type: "error"});
            return false;
        }
        data["cstAccInfoId"] = $("#cstAccInfoId").val();
        data["prjId"] = $("#prjId").val();
        data["cstId"] = $("#cstId").val();
        data["cstNm"] = $("#cstNm").val();
        data["insCode"] = $("#insCode").val();
        data["fundRasInsId"] = $("#fundRasInsId").val();
        data["certNo"] = $("#certNo").val();
        data["certValidSDt"] = $("#certValidSDt").val();//证件有效起始日期
        if (null == certValidEDt) {
            data["certValidEDt"] = $("#certValidEDt").val();//证件有效终止日期
        } else {
            data["certValidEDt"] = certValidEDt;
        }
        data["bkCd"] = liger.get("bkCd").selectedValue;
        data["bkNm"] = liger.get("bkCd").selectedText;
        data["accNo"] =  $("#accNo").val();
        data["mp"] = $("#mp").val();

        var oDate1 = new Date(data["certValidSDt"]);
        var oDate2 = new Date(data["certValidEDt"]);
        if(oDate1.getTime() >= oDate2.getTime()){
            top.$.ligerDialog.SQalert({content: "证件有效起始日期 不能大于等于 证件有效终止日期！", SQ_type: "error"});
            return false;
        }

        var url = '<%=path%>/institution/jxymbank/save.do';
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    //新增时赋值
                    if ($("#cstAccInfoId").val() == "" && msg.data != null && msg.data.prjCstId != null) {
                        $("#cstAccInfoId").val(msg.data.prjCstId);
                    }
                    disabledInput();
                    UIUtils.alertSuccessHold1(msg.info);
                    resetAccResCd();
                    disabledBecaofCheck();
                } else {
                    UIUtils.alertErrorHold1(msg.info);
                }
            }
        });
    }
</script>
</body>
</html>